home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / Maya_lightView_vertex.cg < prev    next >
Encoding:
Text File  |  2003-07-17  |  2.9 KB  |  105 lines

  1. void computeLightViewVectors(
  2.     in float4 inPositionObj,
  3.     in float3 inNormalObj,
  4.     in float3 inTangentObj,
  5.     in float4 inCameraPosObj,
  6. #ifdef IS_DIRECTIONAL_LIGHT
  7.     in float3 lightDirObj,
  8. #else
  9.     in float4 inLightPosObj,
  10. #endif
  11.     out float3 outLightDirTang,
  12.     out float3 outEyeVectorTang)
  13. {
  14.     float3 normal = normalize(inNormalObj);
  15.  
  16. #ifdef INVERT_TANGENT_SPACE
  17.     // If necessary, invert the normal. This is mostly
  18.     // useful when drawing back faces for transparency.
  19.     //
  20.     normal = normal * -1.0;
  21. #endif
  22.     
  23.     float3 tangent = inTangentObj - normal * dot(inTangentObj, normal);
  24.     tangent = normalize(tangent);
  25.  
  26.     float3 binormal = cross(normal, tangent);
  27.     binormal = normalize(binormal);
  28.     
  29.     // Compute the tangent space vectors
  30.     //
  31.  
  32. #ifdef IS_DIRECTIONAL_LIGHT
  33. #else
  34.     float3 lightDirObj = (inLightPosObj - inPositionObj).xyz;
  35. #endif
  36.     outLightDirTang = float3(dot(lightDirObj, tangent), 
  37.                              dot(lightDirObj, binormal),
  38.                              dot(lightDirObj, normal));
  39.     
  40.     // Compute the eye vector in object space (vector from eye to vertex position)
  41.     float3 eyeVectorObj = (inCameraPosObj - inPositionObj).xyz;
  42.     outEyeVectorTang = float3(dot(eyeVectorObj, tangent), 
  43.                               dot(eyeVectorObj, binormal),
  44.                               dot(eyeVectorObj, normal));
  45. }
  46.  
  47. void computeLightVector(
  48.     in float4 inPositionObj,
  49.     in float3 inNormalObj,
  50.     in float3 inTangentObj,
  51. #ifdef IS_DIRECTIONAL_LIGHT
  52.     in float3 lightDirObj,
  53. #else
  54.     in float4 inLightPosObj,
  55. #endif
  56.     out float3 outLightDirTang)
  57. {
  58.     float3 normal = normalize(inNormalObj);
  59.  
  60. #ifdef INVERT_TANGENT_SPACE
  61.     // If necessary, invert the normal. This is mostly
  62.     // useful when drawing back faces for transparency.
  63.     //
  64.     normal = normal * -1.0;
  65. #endif
  66.     
  67.     float3 tangent = inTangentObj - normal * dot(inTangentObj, normal);
  68.     tangent = normalize(tangent);
  69.  
  70.     float3 binormal = cross(normal, tangent);
  71.     binormal = normalize(binormal);
  72.     
  73.     // Compute the tangent space vectors
  74.     //
  75.  
  76. #ifdef IS_DIRECTIONAL_LIGHT
  77. #else
  78.     float3 lightDirObj = (inLightPosObj - inPositionObj).xyz;
  79. #endif
  80.     outLightDirTang = float3(dot(lightDirObj, tangent), 
  81.                              dot(lightDirObj, binormal),
  82.                              dot(lightDirObj, normal));
  83. }
  84.  
  85. void computeTangentToObjMatrix(
  86.     in float3 inNormalObj,
  87.     in float3 inTangentObj,
  88.     out float3x3 outTangentToObjMatrix)
  89. {
  90.     // Compute an orthonormal tangent basis.
  91.     //
  92.  
  93.     float3 normal = normalize(inNormalObj);
  94.     
  95.     float3 tangent = inTangentObj - normal * dot(inTangentObj, normal);
  96.     tangent = normalize(tangent);
  97.     
  98.     float3 binormal = cross(normal, tangent);
  99.     binormal = normalize(binormal);
  100.  
  101.     outTangentToObjMatrix[0] = tangent;
  102.     outTangentToObjMatrix[1] = binormal;
  103.     outTangentToObjMatrix[2] = normal;
  104. }
  105.